package com.app.infra.configuration;

import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.http.DefaultClient;
import com.dahuatech.icc.oauth.http.IClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "app.icc", value = "enabled")
public class IccConfiguration {
    
    @Autowired
    private AppProperties appProperties;
    
    @Bean
    public IClient iccDefaultClient() throws ClientException {
        AppProperties.IccProperties icc = appProperties.getIcc();
        
        
        DefaultClient defaultClient = new DefaultClient(icc.getHost(), icc.getClientId(), icc.getClientSecret());
        return defaultClient;
    }
    
}
